package com.example.flipperview;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import java.util.Arrays;
import java.util.List;


public class MainActivity extends Activity {

    ViewFlipper viewFlipper;
    private Context context ;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        context = this ;

        viewFlipper = (ViewFlipper) findViewById(R.id.view_flipper);
        viewFlipper.setIAdapter(iAdapter);
    }

    @Override
    protected void onResume() {
        super.onResume();
        WkLog.showMsg("onResume");
        viewFlipper.startFlipping();
    }

    @Override
    protected void onPause() {
        super.onPause();
        viewFlipper.stopFlipping();
        WkLog.showMsg("onPause");
    }

    List<String> data = Arrays.asList(
            "1111111111111111111111" ,
            "222" ,
            "333333333333333333333333333333333" ,
            "4444444444444" ,
            "55" ,
            "6" ,
            "7777" ,
            "8888888888888"
            );

    private IAdapter iAdapter = new IAdapter() {

        @Override
        public View getItemView(View convertView, int position) {
            View item   ;
            if (convertView == null) {
                item = View.inflate(context, R.layout.item, null);
            } else {
                item = convertView;
            }

            TextView textView = (TextView) item.findViewById(R.id.textview);
//            textView.setText("测试数据:" + position);
            textView.setText(data.get(position));
            return item;
        }

        @Override
        public int getCount() {
//            return data.size();
            return 5;
        }
    };
}
